package com.zhuiyun.project.api.products.product.controller;

import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.products.product.entity.Sort;
import com.zhuiyun.project.api.products.product.service.SortService;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @ClassName SortController
 * @Description TODO 分类 控制层
 * @Author ypq
 * @Date 2023/10/27 8:30
 **/
@RestController
@Api(tags = "分类管理")
@RequestMapping("/sort")
@Slf4j
public class SortController extends BaseController {

    @Autowired
    private SortService sortService;

    /**
    * @Author ypq
    * @Description 分类的全查方法
    * @Date 2023/10/27 9:12
    * @Return CommonResult
    * @param sort
    */
    @PreAuthorize("@ss.hasPermi('products:sort:list')")
    @ApiOperation(value = "商品分类的全查方法")
    @OptLog(modular = "分类管理", type = CommonConstants.SELECT, describe = "商品分类的全查方法")
    @GetMapping("/listSorts")
    public CommonResult listSorts(Sort sort){
        //将收到的值传入 service进行查询，查询成功返回数据
        return CommonResult.ok(sortService.listSorts(sort));
    }

    /**
    * @Author ypq
    * @Description 商品分类的新增方法
    * @Date 2023/10/27 9:12
    * @Return CommonResult
    * @param sort
    */
    @PreAuthorize("@ss.hasPermi('products:sort:add')")
    @ApiOperation(value = "商品分类的新增方法")
    @OptLog(modular = "分类管理", type = CommonConstants.ADD, describe = "商品分类的新增方法")
    @PostMapping("/addSort")
    public CommonResult addSort(@RequestBody Sort sort){
        //设置创建时间及创建人
        sort.setCreateBy(getLoginName());
        sort.setCreateTime(new Date());
        //设置修改时间及修改人
        sort.setUpdateBy(getLoginName());
        sort.setUpdateTime(new Date());
        //将收到的值传入 service进行新增，成功返回结果
        return CommonResult.ok(sortService.addSort(sort));
    }

    /**
    * @Author ypq
    * @Description 根据二级分类id查询对应三级分类
    * @Date 2023/11/1 18:53
    * @Return CommonResult
    * @param sortId
    */
    @ApiOperation(value = "根据二级分类id查询对应三级分类")
    @GetMapping("/listSortBySortIds")
    public CommonResult listSortBySortIds(Long sortId){
      //将收到的值传入 service进行查询，查询成功返回数据
      return CommonResult.ok(sortService.listSortBySortIds(sortId));
    }
    /**
     * @Author ypq
     * @Description 根据一级分类id查询对应二级分类
     * @Date 2023/11/1 18:53
     * @Return CommonResult
     * @param parentId
     */
    @ApiOperation(value = "根据一级分类id查询对应二级分类")
    @GetMapping("/listSortByParentIds")
    public CommonResult listSortByParentIds(Long parentId){
        //将收到的值传入 service进行查询，查询成功返回数据
        return CommonResult.ok(sortService.listSortByParentIds(parentId));
    }

    /**
    * @Author ypq
    * @Description 查询审核通过的一级分类列表
    * @Date 2023/11/15 19:18
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param sort
    */
    @PreAuthorize("@ss.hasPermi('products:sort:list')")
    @ApiOperation(value = "查询审核通过的一级分类列表")
    @OptLog(modular = "分类管理", type = CommonConstants.SELECT, describe = "查询审核通过的一级分类列表")
    @GetMapping("/listFirstSorts")
    public CommonResult listFirstSorts(Sort sort){
        return CommonResult.ok(sortService.listFirstSorts(sort));
    }

    /**
    * @Author ypq
    * @Description 查询审核通过的二级分类列表
    * @Date 2023/11/15 19:18
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param sort
    */
    @PreAuthorize("@ss.hasPermi('products:sort:list')")
    @ApiOperation(value = "查询审核通过的二级分类列表")
    @OptLog(modular = "分类管理", type = CommonConstants.SELECT, describe = "查询审核通过的二级分类列表")
    @GetMapping("/listSecondSorts")
    public CommonResult listSecondSorts(Sort sort){
        return CommonResult.ok(sortService.listSecondSorts(sort));
    }

    /**
      * @Author hyp
      * @Description 查询一级分类所有数据
      * @Date 2023/11/15 19:29
      * @Return com.zhuiyun.project.common.response.CommonResult
      * @param pageRequest
      * @param sort
    */
    @ApiOperation(value = "查询一级分类所有数据")
    @OptLog(modular = "分类管理" , type = CommonConstants.SELECT , describe = "查询一级分类所有数据")
    @PreAuthorize("@ss.hasPermi('sort:sort:list')")
    @GetMapping("/listSortPrimarys")
    public CommonResult listSortPrimarys(PageRequest pageRequest,Sort sort){
        return CommonResult.ok(sortService.listSortPrimarys(pageRequest,sort));
    }

    /**
     * @Author hyp
     * @Description 查询二级分类所有数据
     * @Date 2023/11/15 19:29
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param pageRequest
     * @param sort
     */
    @ApiOperation(value = "查询二级分类所有数据")
    @OptLog(modular = "分类管理" , type = CommonConstants.SELECT , describe = "查询二级分类所有数据")
    @PreAuthorize("@ss.hasPermi('sort:sort:list')")
    @GetMapping("/listSortSecondarys")
    public CommonResult listSortSecondarys(PageRequest pageRequest,Sort sort){
        return CommonResult.ok(sortService.listSortSecondarys(pageRequest,sort));
    }
    /**
     * @Author hyp
     * @Description 查询三级分类所有数据
     * @Date 2023/11/15 19:29
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param pageRequest
     * @param sort
     */
    @ApiOperation(value = "查询三级分类所有数据")
    @OptLog(modular = "分类管理" , type = CommonConstants.SELECT , describe = "查询三级分类所有数据")
    @PreAuthorize("@ss.hasPermi('sort:sort:list')")
    @GetMapping("/listSortThreeLevels")
    public CommonResult listSortThreeLevels(PageRequest pageRequest, Sort sort){
        return CommonResult.ok(sortService.listSortThreeLevels(pageRequest,sort));
    }

    /**
      * @Author hyp
      * @Description 查询所有分类
      * @Date 2023/11/22 20:41
      * @Return
    */
    @PreAuthorize("@ss.hasPermi('sort:sort:list')")
    @GetMapping("/listSortAll")
    @ApiOperation(value = "查询所有分类")
    @OptLog(modular = "分类管理" , type = CommonConstants.SELECT, describe = "查询所有分类")
    public CommonResult listSortAll(){
        return CommonResult.ok(sortService.listSortAll());
    }


    /**
      * @Author hyp
      * @Description 根据分类id通过审批
      * @Date 2023/11/15 19:31
      * @Return com.zhuiyun.project.common.response.CommonResult
      * @param sortId
    */
    @ApiOperation(value = "根据分类id通过审批")
    @OptLog(modular = "分类管理" , type = CommonConstants.UPDATE , describe = "根据分类id通过审批")
    @PreAuthorize("@ss.hasPermi('sort:sort:edit')")
    @PutMapping("/editApproval/{sortId}")
    public CommonResult editApproval(@PathVariable Long sortId){
        return CommonResult.ok(sortService.editApproval(sortId));
    }

    /**
      * @Author hyp
      * @Description 根据分类id驳回审批
      * @Date 2023/11/15 19:32
      * @Return com.zhuiyun.project.common.response.CommonResult
      * @param sortId
    */
    @ApiOperation(value = "根据分类id驳回审批")
    @OptLog(modular = "分类管理" , type = CommonConstants.UPDATE , describe = "根据分类id驳回审批")
    @PreAuthorize("@ss.hasPermi('sort:sort:edit')")
    @PutMapping("/editReject/{sortId}")
    public CommonResult editReject(@PathVariable Long sortId){
        return CommonResult.ok(sortService.editReject(sortId));
    }

    /**
      * @Author hyp
      * @Description 根据分类id查询
      * @Date 2023/11/15 19:33
      * @Return com.zhuiyun.project.common.response.CommonResult
      * @param sortId
    */

    @ApiOperation(value = "根据分类id查询")
    @OptLog(modular = "分类管理" , type = CommonConstants.SELECT , describe = "根据分类id查询")
    @PreAuthorize("@ss.hasPermi('sort:sort:query')")
    @GetMapping("/getSortById/{sortId}")
    public CommonResult getSortById(@PathVariable Long sortId){
        return CommonResult.ok(sortService.getSortById(sortId));
    }

    /**
      * @Author hyp
      * @Description 根据分类id重置审批
      * @Date 2023/11/15 19:34
      * @Return com.zhuiyun.project.common.response.CommonResult
      * @param sortId
    */
    @ApiOperation(value = "根据分类id重置审批")
    @OptLog(modular = "分类管理" , type = CommonConstants.UPDATE , describe = "根据分类id重置审批")
    @PreAuthorize("@ss.hasPermi('sort:sort:edit')")
    @PutMapping("/resetApproval/{sortId}")
    public CommonResult resetApproval(@PathVariable Long sortId){
        return CommonResult.ok(sortService.resetApproval(sortId));
    }
}
